﻿using BlockeyEssentials.ScreenSystem;
using Microsoft.Xna.Framework.Graphics;
using BlockeyEssentials.Input;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework;

namespace Blockey.MenuSystemScreens
{
    public class EditTeamInfoScreen : Screen
    {
        public EditTeamInfoScreen(ScreenManager oManager, bool oIsNewTeam)
            : base(oManager)
        {
            _IsNewTeam = oIsNewTeam;

            // Team Name
            // Team City
            // Team Motto
        }

        public override void Update()
        {
            if (Active)
            {
                Input();
            }
        }

        public override void Draw(SpriteBatch oSB)
        {
        }

        private void Input()
        {
            var oUp = false;
            var oDown = false;
            var oSelect = false;
            var oCancel = false;

            var oKeyboardInput = InputManager.Keyboard;
            if (oKeyboardInput.JustPressed(Keys.Up))
                oUp = true;
            if (oKeyboardInput.JustPressed(Keys.Down))
                oDown = true;
            if (oKeyboardInput.JustPressed(Keys.Enter, Keys.F))
                oSelect = true;
            if (oKeyboardInput.JustPressed(Keys.D))
                oCancel = true;

            var oGamePadInput = InputManager.GamePad1;
            if (oGamePadInput.JustPressed(Buttons.DPadUp))
                oUp = true;
            if (oGamePadInput.JustPressed(Buttons.DPadDown))
                oDown = true;
            if (oGamePadInput.JustPressed(Buttons.A))
                oSelect = true;
            if (oGamePadInput.JustPressed(Buttons.B))
                oCancel = true;

            if (oUp)
            {
                _Index--;
                if (_Index < 0)
                    _Index = 3;
            }

            if (oDown)
            {
                _Index++;
                if (_Index > 3)
                    _Index = 0;
            }

            if (oSelect)
            {
                Select();
                return;
            }

            if (oCancel)
            {
                Cancel();
                return;
            }
        }

        private void Select()
        {
            switch (_Index)
            {
                case 0: // Name
                    {
                        //Guide.BeginShowKeyboardInput(
                        //    PlayerIndex.One, 
                        //    "Team Name", 
                        //    "Enter the name for your team",
                        //    _TeamName, 
                        //    );
                        break;
                    }
                case 1: // Location
                    {
                        //Guide.BeginShowKeyboardInput(
                        //    PlayerIndex.One, 
                        //    "Team Location", 
                        //    "Enter the location of your team",
                        //    _TeamLocation, 
                        //    );
                        break;
                    }
                case 2: // Motto
                    {
                        //Guide.BeginShowKeyboardInput(
                        //    PlayerIndex.One, 
                        //    "Team Motto", 
                        //    "Enter a motto for your team",
                        //    _TeamMotto, 
                        //    );
                        break;
                    }
                case 3: // Back
                    {
                        break;
                    }
            }
        }

        private void Cancel()
        {

        }

        private string _TeamName;
        private string _TeamLocation;
        private string _TeamMotto;

        private int _Index;

        private bool _IsNewTeam;
    }
}
